package com.yunweiweishi.xuhuanpaltform.yuhuan_app.controller;


import com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf.CommonResult;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.FlightsTask;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.FlightsTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "班次任务", tags = {"班次任务controller"})
@RestController
@RequestMapping("/FlightsTask")
public class FlightsTaskController {



    @Autowired
    private CommonResult result;


    @Autowired
    private FlightsTaskService flightsTaskService;


//
//    @GetMapping("/findFlightsTaskByName")
//    public CommonResult findFlightsTaskByName(@RequestParam ("userId") Long userId,
//                                              @RequestParam ("flightsId") Long flightsId,
//                                              @RequestParam ("startTime") Date startTime,
//                                              @RequestParam ("endTime") Date endTime
//                                              ) {
//
//        try {
//
//            FlightsTask flightsTask = flightsTaskService.findFlightsTaskByName(userId, flightsId, startTime, endTime);
//            result.setData(flightsTask);
//
//            return result;
//        } catch (Exception e) {
//            e.printStackTrace();
//            result.setState(500);
//            result.setMsg("失败");
//            return result;
//        }
//    }



    @ApiOperation( value = "查询任务列表")
    @GetMapping("/flightsTaskList")
    public CommonResult FindAll(  ) {

        try {

            List<FlightsTask>  flightsTaskList = flightsTaskService.FindAllList();
            result.setData(flightsTaskList);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }


    }





    @PostMapping("addFlightsTask")
    public CommonResult addFlightsTask(@RequestBody FlightsTask flightsTask) {


        try {

           flightsTaskService.addFlightsTask(flightsTask);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }
    }
    /**
     * 通过id进行更新
     *
     * @param
     * @return
     */
    @PutMapping("updateFlightsTaskById/{id}")
    public CommonResult updateFlightsTaskById(@RequestBody FlightsTask flightsTask ) {

        try {
            flightsTaskService.updateFlightsTaskById(flightsTask);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    /**
     * 通过id进行删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteFlightsTaskById")
    public CommonResult deleteFlightsTaskById(@RequestParam("id") Long id) {


        try {
            flightsTaskService.deleteFlightsTaskById(id);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }
}
